import _ from 'lodash'
import useYear from '@screen/hooks/useYear'
// 分页获取数据参数
export function generatePageParams(
  isPage = false,
  pageSize = 5,
  other: Record<string, any> = {},
) {
  const { year } = useYear()
  if (!isPage)
    return {
      year: year.value,
      ...other,
    }
  return {
    currentPage: 1,
    pageSize,
    query: {
      year: year.value,
      ...other,
    },
  }
}

const designWidth = 1920
const designHeight = 1080
const precision = 5

export function vw(val: number, hasUnit?: true): string
export function vw(val: number, hasUnit?: false): number
export function vw(val: number, hasUnit?: boolean): string | number
export function vw(val: number, hasUnit = true) {
  if (!val) return 0
  const result = _.divide(val * 100, designWidth)
  const lastResult = _.round(result, precision)
  if (!hasUnit) return lastResult
  return lastResult + 'vw'
}

export function vh(val: number) {
  if (!val) return 0
  const result = _.divide(val * 100, designHeight)
  return _.round(result, precision) + 'vh'
}
